package com.company.bookstore.common.judgeUtils;

/**
 * <p>
 * 条件判断工具类
 * </p>
 *
 * @author 姬深威
 * @since 2020-09-20
 */
public class JudgeUtils {

    /**
     * 用于判断 按什么顺序排列
     *
     * @param orderType 0按ID顺序排序 1综合排序（其实是随机排序） 2销量降序 3价格从低到高 4价格从高到低
     * @return 返回的是可以拼接到sql语句中的字符串
     */
    public static String judgeOrderType(Integer orderType) {
        String orderType1 = "";
        if (orderType == 0) {
            orderType1 = "id ASC";
        } else if (orderType == 1) {
            orderType1 = "RAND()";
        } else if (orderType == 2) {
            orderType1 = "sales DESC";
        } else if (orderType == 3) {
            orderType1 = "price ASC";
        } else {
            orderType1 = "price DESC";
        }
        return orderType1;
    }

    /**
     * 判断from 和 to是否为空，如果其一为空则给空值赋值。如果两者都为空则不管，直接交给动态sql判断

    public static void isFromToNull(Integer from, Integer to) {
        if (from == null && to != null) {
            FROM = 0;
            TO = to;
        } else if (from != null && to == null) {
            FROM = from;
            TO = 99999;
        } else {
            FROM = from;
            TO = to;
        }
    }*/
}
